//
//  TPProductWebViewCell.m
//  Yimei
//
//  Created by xiaowu xiaowu on 2017/10/25.
//  Copyright © 2017年 xiaowu xiaowu. All rights reserved.
//

#import "TPProductWebViewCell.h"

@implementation TPProductWebViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setup];
    }
    return self;
}


-(void)setup{
    
    
    NSString *jSString = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
    
    WKUserScript *wkUserScript = [[WKUserScript alloc] initWithSource:jSString injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
    // 自定义配置，一般用于js调用oc方法（oc拦截URL中的数据做自定义操作）
    WKUserContentController *userContentController = [[WKUserContentController alloc] init];
    [userContentController addUserScript:wkUserScript];
    
    WKWebViewConfiguration *figuration = [[WKWebViewConfiguration alloc]init];
    figuration.userContentController = userContentController;
    
    self.webView = [[WKWebView alloc]initWithFrame:CGRectZero configuration:figuration];
    _webView.userInteractionEnabled = NO;
    [_webView sizeToFit];
    //    self.webView.UIDelegate = self;
    //    _webView.navigationDelegate = self;
    [self.contentView addSubview:self.webView];
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10.0);
        make.right.mas_equalTo(-10.0);
        make.top.mas_equalTo(15.0);
        //        make.height.mas_equalTo(10.0);
        make.bottom.mas_equalTo(-15.0);
    }];
    
    [self.webView tp_stopAnimating];
    
    
    //    [_webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
}
@end
